package com.introse.student;

import java.util.ArrayList;
import java.util.Calendar;

/**ClassDay represents a day full of classes. These classes have start and end times, which are covered by the ClassTime class**/
public class ClassDay {
	/**Static constant representing Monday**/
	public static final int MONDAY = 1;
	/**Static constant representing Tuesday**/
	public static final int TUESDAY = 2;
	/**Static constant representing Wednesday**/
	public static final int WEDNESDAY = 3;
	/**Static constant representing Thursday**/
	public static final int THURSDAY = 4;
	/**Static constant representing Friday**/
	public static final int	FRIDAY = 5;
	/**Static constant representing Saturday**/
	public static final int	SATURDAY = 6;
	
	/**The day of the week that the ClassDay represents**/
	private int dayOfWeek;
	/**The times of the day that have classes/the student is busy**/
	private ArrayList<ClassTime> times;
	
	public ClassDay(int dayOfWeek, ClassTime... classTimes) {
		this.dayOfWeek = dayOfWeek;
		this.times = new ArrayList<ClassTime>();
		if (classTimes != null) {
			for (ClassTime time : classTimes) {
				this.times.add(time);
			}
		}
	}
	
	public void addClassTime(ClassTime classTime) {
		this.times.add(classTime);
	}
	
	public void addClassTime(Calendar classStartTime, Calendar classEndTime) throws Exception {
		if (!ClassTime.hasConflict(classStartTime, classEndTime, times)) {
		this.times.add(new ClassTime(classStartTime, classEndTime));
		}
		else {
			System.out.println("addClassTime(): There is a conflict of times!");
			throw new Exception();
		}
	}
	
	public void addClassTime(int classStartHour, int classStartMinute, int classEndHour, int classEndMinute) throws Exception {
		Calendar startTime = Calendar.getInstance();
		startTime.clear();
		startTime.set(Calendar.HOUR_OF_DAY, classStartHour);
		startTime.set(Calendar.MINUTE, classStartMinute);
		startTime.set(Calendar.SECOND, 0);
		Calendar endTime = Calendar.getInstance();
		endTime.set(Calendar.HOUR_OF_DAY, classEndHour);
		endTime.set(Calendar.MINUTE, classEndMinute);
		endTime.set(Calendar.SECOND, 0);
		addClassTime(startTime, endTime);
	}
	
	/**Get all the ClassTime's in an ArrayList for the day
	 * 
	 * @return The collection of ClassTime objects assigned for this ClassDay object
	 */
	public ArrayList<ClassTime> getClassTimes() {
		return times;
	}
	
	/**Get the day of the week (raw constant)
	 * 
	 * @return The raw constant assigned to the ClassDay class.
	 */
	public int getDayOfWeek () {
		return this.dayOfWeek;
	}
	
	/**Get the day of the week in String format
	 * 
	 * @param dayOfWeek One of the constants belonging to ClassDay class
	 * @return The string representation of the constants
	 */
	public static String getDayOfWeekString (int dayOfWeek) {
		switch(dayOfWeek) {
		case MONDAY:
			return "Monday";
		case TUESDAY:
			return "Tuesday";
		case WEDNESDAY:
			return "Wednesday";
		case THURSDAY:
			return "Thursday";
		case FRIDAY:
			return "Friday";
		}
		System.out.println("Null string from getDayOfWeekString!");
		return null;
	}
	
	/**Gets the day of the week assigned to this ClassDay object in String format
	 * 
	 * @return The string representation of the ClassDay object's current day of the week.
	 */
	public String getDayOfWeekString () {
		return getDayOfWeekString(this.dayOfWeek);
	}
	
}
